/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package midlet;

import controller.CuentaController;
import controller.MovimientoController;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import persistence.Cuenta;
import persistence.Movimiento;
import util.DateUtil;

/**
 * @author alfredo
 */
public class ControlTarjeta extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    MovimientoController movimientoController;
    CuentaController cuentaController;
    boolean esEntrada = true;
    int reportIndex;
    int reportPageSize = 5;
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private java.util.Hashtable __previousDisplayables = new java.util.Hashtable();
    private Command exitCommand;
    private Command okCommand;
    private Command itemCommand;
    private Command itemCommand1;
    private Command cancelCommand;
    private Command ingresarCommand;
    private Command backCommand;
    private Command backCommand1;
    private Command backCommand2;
    private Command screenCommand;
    private Command backCommand4;
    private Command backCommand3;
    private Command backCommand5;
    private Command prevItemCommand;
    private Command nextItemCommand;
    private Command backCommand6;
    private Command prevItemCommand1;
    private Command nextItemCommand1;
    private Form main;
    private StringItem stringItem;
    private ImageItem imageItem;
    private List movimientoList;
    private Form registrarEntradaForm;
    private TextField montoTextField;
    private TextField referenciaTextField;
    private DateField fechaDateField;
    private Form consultaMovimientosForm;
    private Form consultaSaldoForm;
    private Image image2;
    private Image image1;
    private Image image4;
    private Image image3;
    private Image image5;
    private Image image;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The ControlTarjeta constructor.
     */
    public ControlTarjeta() {
        movimientoController = new MovimientoController();
        cuentaController = new CuentaController();
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    /**
     * Switches a display to previous displayable of the current displayable.
     * The <code>display</code> instance is obtain from the <code>getDisplay</code> method.
     */
    private void switchToPreviousDisplayable() {
        Displayable __currentDisplayable = getDisplay().getCurrent();
        if (__currentDisplayable != null) {
            Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable);
            if (__nextDisplayable != null) {
                switchDisplayable(null, __nextDisplayable);
            }
        }
    }
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getMain());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        Displayable __currentDisplayable = display.getCurrent();
        if (__currentDisplayable != null  &&  nextDisplayable != null) {
            __previousDisplayables.put(nextDisplayable, __currentDisplayable);
        }
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == consultaMovimientosForm) {//GEN-BEGIN:|7-commandAction|1|74-preAction
            if (command == backCommand3) {//GEN-END:|7-commandAction|1|74-preAction
                // write pre-action user code here
                switchDisplayable(null, getMovimientoList());//GEN-LINE:|7-commandAction|2|74-postAction
                // write post-action user code here
            } else if (command == nextItemCommand) {//GEN-LINE:|7-commandAction|3|91-preAction
                // write pre-action user code here
                consultaMovimientosForm = null;
                reportIndex++;
                switchDisplayable(null, getConsultaMovimientosForm());
//GEN-LINE:|7-commandAction|4|91-postAction
                // write post-action user code here
            } else if (command == prevItemCommand) {//GEN-LINE:|7-commandAction|5|93-preAction
                // write pre-action user code here
                consultaMovimientosForm = null;
                reportIndex--;
                if (reportIndex < 0) {
                    reportIndex = 0;
                }
                switchDisplayable(null, getConsultaMovimientosForm());
//GEN-LINE:|7-commandAction|6|93-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|7|110-preAction
        } else if (displayable == consultaSaldoForm) {
            if (command == backCommand6) {//GEN-END:|7-commandAction|7|110-preAction
                // write pre-action user code here
                switchDisplayable(null, getMovimientoList());//GEN-LINE:|7-commandAction|8|110-postAction
                // write post-action user code here
            } else if (command == nextItemCommand1) {//GEN-LINE:|7-commandAction|9|106-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|10|106-postAction
                // write post-action user code here
            } else if (command == prevItemCommand1) {//GEN-LINE:|7-commandAction|11|108-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|12|108-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|13|19-preAction
        } else if (displayable == main) {
            if (command == exitCommand) {//GEN-END:|7-commandAction|13|19-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|14|19-postAction
                // write post-action user code here
            } else if (command == okCommand) {//GEN-LINE:|7-commandAction|15|23-preAction
                // write pre-action user code here
                switchDisplayable(null, getMovimientoList());//GEN-LINE:|7-commandAction|16|23-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|26-preAction
        } else if (displayable == movimientoList) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|17|26-preAction
                // write pre-action user code here
                movimientoListAction();//GEN-LINE:|7-commandAction|18|26-postAction
                // write post-action user code here
            } else if (command == backCommand5) {//GEN-LINE:|7-commandAction|19|85-preAction
                // write pre-action user code here
                switchDisplayable(null, getMain());//GEN-LINE:|7-commandAction|20|85-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|21|80-preAction
        } else if (displayable == registrarEntradaForm) {
            if (command == backCommand4) {//GEN-END:|7-commandAction|21|80-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|22|80-postAction
                // write post-action user code here
            } else if (command == ingresarCommand) {//GEN-LINE:|7-commandAction|23|42-preAction
                // write pre-action user code here
                movimientoController.create();
                movimientoController.getMovimiento().setReferencia(getReferenciaTextField().getString());
                if (esEntrada) {
                    movimientoController.getMovimiento().setMonto(Float.parseFloat(getMontoTextField().getString()));
                } else {
                    movimientoController.getMovimiento().setMonto(Float.parseFloat(getMontoTextField().getString()) * -1);
                }
                movimientoController.getMovimiento().setFecha(getFechaDateField().getDate());
                movimientoController.save();

                cuentaController.create();

                cuentaController.addMovimiento(movimientoController.getMovimiento());

                switchDisplayable(null, getMovimientoList());//GEN-LINE:|7-commandAction|24|42-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|25|7-postCommandAction
        }//GEN-END:|7-commandAction|25|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|26|
    //</editor-fold>//GEN-END:|7-commandAction|26|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            exitCommand = new Command("Salir", Command.EXIT, 1);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|18-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: main ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of main component.
     * @return the initialized component instance
     */
    public Form getMain() {
        if (main == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            main = new Form("Control Tarjeta", new Item[] { getStringItem(), getImageItem() });//GEN-BEGIN:|14-getter|1|14-postInit
            main.addCommand(getExitCommand());
            main.addCommand(getOkCommand());
            main.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return main;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|16-getter|0|16-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|16-getter|0|16-preInit
            // write pre-init user code here
            stringItem = new StringItem("Bienvenido! ", "Presione aceptar para continuar", Item.PLAIN);//GEN-BEGIN:|16-getter|1|16-postInit
            stringItem.setLayout(ImageItem.LAYOUT_LEFT | Item.LAYOUT_TOP | Item.LAYOUT_VCENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_SHRINK | Item.LAYOUT_VSHRINK | Item.LAYOUT_EXPAND | Item.LAYOUT_VEXPAND);//GEN-END:|16-getter|1|16-postInit
            // write post-init user code here
        }//GEN-BEGIN:|16-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|16-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|22-getter|0|22-preInit
    /**
     * Returns an initiliazed instance of okCommand component.
     * @return the initialized component instance
     */
    public Command getOkCommand() {
        if (okCommand == null) {//GEN-END:|22-getter|0|22-preInit
            // write pre-init user code here
            okCommand = new Command("Entrar", Command.OK, 0);//GEN-LINE:|22-getter|1|22-postInit
            // write post-init user code here
        }//GEN-BEGIN:|22-getter|2|
        return okCommand;
    }
    //</editor-fold>//GEN-END:|22-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|29-getter|0|29-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|29-getter|0|29-preInit
            // write pre-init user code here
            itemCommand = new Command("Registrar salida", Command.ITEM, 0);//GEN-LINE:|29-getter|1|29-postInit
            // write post-init user code here
        }//GEN-BEGIN:|29-getter|2|
        return itemCommand;
    }
    //</editor-fold>//GEN-END:|29-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand1 ">//GEN-BEGIN:|31-getter|0|31-preInit
    /**
     * Returns an initiliazed instance of itemCommand1 component.
     * @return the initialized component instance
     */
    public Command getItemCommand1() {
        if (itemCommand1 == null) {//GEN-END:|31-getter|0|31-preInit
            // write pre-init user code here
            itemCommand1 = new Command("Registrar entrada", Command.ITEM, 0);//GEN-LINE:|31-getter|1|31-postInit
            // write post-init user code here
        }//GEN-BEGIN:|31-getter|2|
        return itemCommand1;
    }
    //</editor-fold>//GEN-END:|31-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: movimientoList ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of movimientoList component.
     * @return the initialized component instance
     */
    public List getMovimientoList() {
        if (movimientoList == null) {//GEN-END:|24-getter|0|24-preInit
            // write pre-init user code here
            movimientoList = new List("Movimientos", Choice.IMPLICIT);//GEN-BEGIN:|24-getter|1|24-postInit
            movimientoList.append("Registrar entrada", getImage2());
            movimientoList.append("Registrar salida", getImage3());
            movimientoList.append("Consultar Movimientos", getImage4());
            movimientoList.append("Consultar Saldos", getImage5());
            movimientoList.addCommand(getBackCommand5());
            movimientoList.setCommandListener(this);
            movimientoList.setSelectedFlags(new boolean[] { false, false, false, false });//GEN-END:|24-getter|1|24-postInit
            // write post-init user code here
        }//GEN-BEGIN:|24-getter|2|
        return movimientoList;
    }
    //</editor-fold>//GEN-END:|24-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: movimientoListAction ">//GEN-BEGIN:|24-action|0|24-preAction
    /**
     * Performs an action assigned to the selected list element in the movimientoList component.
     */
    public void movimientoListAction() {//GEN-END:|24-action|0|24-preAction
        // enter pre-action user code here
        String __selectedString = getMovimientoList().getString(getMovimientoList().getSelectedIndex());//GEN-BEGIN:|24-action|1|33-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Registrar entrada")) {//GEN-END:|24-action|1|33-preAction
                // write pre-action user code here
                esEntrada = true;
                referenciaTextField = null;
                montoTextField = null;
                fechaDateField = null;
                registrarEntradaForm = null;
                switchDisplayable(null, getRegistrarEntradaForm());//GEN-LINE:|24-action|2|33-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Registrar salida")) {//GEN-LINE:|24-action|3|34-preAction
                // write pre-action user code here
                esEntrada = false;
                referenciaTextField = null;
                montoTextField = null;
                fechaDateField = null;
                registrarEntradaForm = null;
                switchDisplayable(null, getRegistrarEntradaForm());//GEN-LINE:|24-action|4|34-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Consultar Movimientos")) {//GEN-LINE:|24-action|5|56-preAction
                // write pre-action user code here
                consultaMovimientosForm = null;
                reportIndex = 0;
                switchDisplayable(null, getConsultaMovimientosForm());//GEN-LINE:|24-action|6|56-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Consultar Saldos")) {//GEN-LINE:|24-action|7|100-preAction
                // write pre-action user code here
                consultaSaldoForm = null;
                reportIndex = 0;
                switchDisplayable(null, getConsultaSaldoForm());//GEN-LINE:|24-action|8|100-postAction
                // write post-action user code here
            }//GEN-BEGIN:|24-action|9|24-postAction
        }//GEN-END:|24-action|9|24-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|24-action|10|
    //</editor-fold>//GEN-END:|24-action|10|

    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: registrarEntradaForm ">//GEN-BEGIN:|35-getter|0|35-preInit
    /**
     * Returns an initiliazed instance of registrarEntradaForm component.
     * @return the initialized component instance
     */
    public Form getRegistrarEntradaForm() {
        if (registrarEntradaForm == null) {//GEN-END:|35-getter|0|35-preInit
            // write pre-init user code here
            registrarEntradaForm = new Form("Registrar Entrada", new Item[] { getReferenciaTextField(), getMontoTextField(), getFechaDateField() });//GEN-BEGIN:|35-getter|1|35-postInit
            registrarEntradaForm.addCommand(getIngresarCommand());
            registrarEntradaForm.addCommand(getBackCommand4());
            registrarEntradaForm.setCommandListener(this);//GEN-END:|35-getter|1|35-postInit
            // write post-init user code here
            registrarEntradaForm.setTitle("Registrar " + (esEntrada ? "Entrada" : "Salida"));
        }//GEN-BEGIN:|35-getter|2|
        return registrarEntradaForm;
    }
    //</editor-fold>//GEN-END:|35-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cancelCommand ">//GEN-BEGIN:|43-getter|0|43-preInit
    /**
     * Returns an initiliazed instance of cancelCommand component.
     * @return the initialized component instance
     */
    public Command getCancelCommand() {
        if (cancelCommand == null) {//GEN-END:|43-getter|0|43-preInit
            // write pre-init user code here
            cancelCommand = new Command("Cancelar", Command.CANCEL, 0);//GEN-LINE:|43-getter|1|43-postInit
            // write post-init user code here
        }//GEN-BEGIN:|43-getter|2|
        return cancelCommand;
    }
    //</editor-fold>//GEN-END:|43-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|45-getter|0|45-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|45-getter|0|45-preInit
            // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|45-getter|1|45-postInit
            // write post-init user code here
        }//GEN-BEGIN:|45-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|45-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|52-getter|0|52-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|52-getter|0|52-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|52-getter|1|52-postInit
            // write post-init user code here
        }//GEN-BEGIN:|52-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|52-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            backCommand2 = new Command("Back", Command.BACK, 0);//GEN-LINE:|69-getter|1|69-postInit
            // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return backCommand2;
    }
    //</editor-fold>//GEN-END:|69-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: consultaMovimientosForm ">//GEN-BEGIN:|63-getter|0|63-preInit
    /**
     * Returns an initiliazed instance of consultaMovimientosForm component.
     * @return the initialized component instance
     */
    public Form getConsultaMovimientosForm() {
        if (consultaMovimientosForm == null) {//GEN-END:|63-getter|0|63-preInit
            // write pre-init user code here
            consultaMovimientosForm = new Form("Consulta Movimientos", new Item[] { });//GEN-BEGIN:|63-getter|1|63-postInit
            consultaMovimientosForm.addCommand(getBackCommand3());
            consultaMovimientosForm.addCommand(getNextItemCommand());
            consultaMovimientosForm.addCommand(getPrevItemCommand());
            consultaMovimientosForm.setCommandListener(this);//GEN-END:|63-getter|1|63-postInit

            Movimiento[] mm = movimientoController.list(reportIndex, reportPageSize);
            if (mm != null) {
                consultaMovimientosForm.append(new StringItem("Pagina " + (reportIndex+1), "\n"));
                for (int i = 0; i < mm.length; i++) {
                    consultaMovimientosForm.append(new StringItem("\n" + DateUtil.dateToString(mm[i].getFecha()), "\n" + mm[i].getReferencia() + "  " + mm[i].getMonto() + "\n"));
                    consultaMovimientosForm.append(new Spacer(16, 2));
                }
            } else {
                consultaMovimientosForm.append(new StringItem("No se encontraron registros.", ""));
            }
            // write post-init user code here
        }//GEN-BEGIN:|63-getter|2|
        return consultaMovimientosForm;
    }
    //</editor-fold>//GEN-END:|63-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|73-getter|0|73-preInit
    /**
     * Returns an initiliazed instance of backCommand3 component.
     * @return the initialized component instance
     */
    public Command getBackCommand3() {
        if (backCommand3 == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
            backCommand3 = new Command("Atras", Command.BACK, 1);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here
        }//GEN-BEGIN:|73-getter|2|
        return backCommand3;
    }
    //</editor-fold>//GEN-END:|73-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ingresarCommand ">//GEN-BEGIN:|41-getter|0|41-preInit
    /**
     * Returns an initiliazed instance of ingresarCommand component.
     * @return the initialized component instance
     */
    public Command getIngresarCommand() {
        if (ingresarCommand == null) {//GEN-END:|41-getter|0|41-preInit
            // write pre-init user code here
            ingresarCommand = new Command("Ingresar", Command.SCREEN, 0);//GEN-LINE:|41-getter|1|41-postInit
            // write post-init user code here
        }//GEN-BEGIN:|41-getter|2|
        return ingresarCommand;
    }
    //</editor-fold>//GEN-END:|41-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: montoTextField ">//GEN-BEGIN:|38-getter|0|38-preInit
    /**
     * Returns an initiliazed instance of montoTextField component.
     * @return the initialized component instance
     */
    public TextField getMontoTextField() {
        if (montoTextField == null) {//GEN-END:|38-getter|0|38-preInit
            // write pre-init user code here
            montoTextField = new TextField("Monto", null, 32, TextField.DECIMAL);//GEN-LINE:|38-getter|1|38-postInit
            // write post-init user code here
        }//GEN-BEGIN:|38-getter|2|
        return montoTextField;
    }
    //</editor-fold>//GEN-END:|38-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: referenciaTextField ">//GEN-BEGIN:|37-getter|0|37-preInit
    /**
     * Returns an initiliazed instance of referenciaTextField component.
     * @return the initialized component instance
     */
    public TextField getReferenciaTextField() {
        if (referenciaTextField == null) {//GEN-END:|37-getter|0|37-preInit
            // write pre-init user code here
            referenciaTextField = new TextField("Referencia", null, 32, TextField.ANY);//GEN-LINE:|37-getter|1|37-postInit
            // write post-init user code here

        }//GEN-BEGIN:|37-getter|2|
        return referenciaTextField;
    }
    //</editor-fold>//GEN-END:|37-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: fechaDateField ">//GEN-BEGIN:|40-getter|0|40-preInit
    /**
     * Returns an initiliazed instance of fechaDateField component.
     * @return the initialized component instance
     */
    public DateField getFechaDateField() {
        if (fechaDateField == null) {//GEN-END:|40-getter|0|40-preInit
            // write pre-init user code here
            fechaDateField = new DateField("Fecha", DateField.DATE_TIME);//GEN-BEGIN:|40-getter|1|40-postInit
            fechaDateField.setDate(new java.util.Date(System.currentTimeMillis()));//GEN-END:|40-getter|1|40-postInit
            // write post-init user code here
        }//GEN-BEGIN:|40-getter|2|
        return fechaDateField;
    }
    //</editor-fold>//GEN-END:|40-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: screenCommand ">//GEN-BEGIN:|77-getter|0|77-preInit
    /**
     * Returns an initiliazed instance of screenCommand component.
     * @return the initialized component instance
     */
    public Command getScreenCommand() {
        if (screenCommand == null) {//GEN-END:|77-getter|0|77-preInit
            // write pre-init user code here
            screenCommand = new Command("Screen", Command.SCREEN, 0);//GEN-LINE:|77-getter|1|77-postInit
            // write post-init user code here
        }//GEN-BEGIN:|77-getter|2|
        return screenCommand;
    }
    //</editor-fold>//GEN-END:|77-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand4 ">//GEN-BEGIN:|79-getter|0|79-preInit
    /**
     * Returns an initiliazed instance of backCommand4 component.
     * @return the initialized component instance
     */
    public Command getBackCommand4() {
        if (backCommand4 == null) {//GEN-END:|79-getter|0|79-preInit
            // write pre-init user code here
            backCommand4 = new Command("Atras", Command.BACK, 1);//GEN-LINE:|79-getter|1|79-postInit
            // write post-init user code here
        }//GEN-BEGIN:|79-getter|2|
        return backCommand4;
    }
    //</editor-fold>//GEN-END:|79-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem ">//GEN-BEGIN:|82-getter|0|82-preInit
    /**
     * Returns an initiliazed instance of imageItem component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem() {
        if (imageItem == null) {//GEN-END:|82-getter|0|82-preInit
            // write pre-init user code here
            imageItem = new ImageItem("", getImage1(), ImageItem.LAYOUT_CENTER, "<Missing Image>", Item.PLAIN);//GEN-LINE:|82-getter|1|82-postInit
            // write post-init user code here
        }//GEN-BEGIN:|82-getter|2|
        return imageItem;
    }
    //</editor-fold>//GEN-END:|82-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">//GEN-BEGIN:|83-getter|0|83-preInit
    /**
     * Returns an initiliazed instance of image1 component.
     * @return the initialized component instance
     */
    public Image getImage1() {
        if (image1 == null) {//GEN-END:|83-getter|0|83-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|83-getter|1|83-@java.io.IOException
                image1 = Image.createImage("/img/chequemax.jpg");
            } catch (java.io.IOException e) {//GEN-END:|83-getter|1|83-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|83-getter|2|83-postInit
            // write post-init user code here
        }//GEN-BEGIN:|83-getter|3|
        return image1;
    }
    //</editor-fold>//GEN-END:|83-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand5 ">//GEN-BEGIN:|84-getter|0|84-preInit
    /**
     * Returns an initiliazed instance of backCommand5 component.
     * @return the initialized component instance
     */
    public Command getBackCommand5() {
        if (backCommand5 == null) {//GEN-END:|84-getter|0|84-preInit
            // write pre-init user code here
            backCommand5 = new Command("Atras", Command.BACK, 0);//GEN-LINE:|84-getter|1|84-postInit
            // write post-init user code here
        }//GEN-BEGIN:|84-getter|2|
        return backCommand5;
    }
    //</editor-fold>//GEN-END:|84-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image2 ">//GEN-BEGIN:|87-getter|0|87-preInit
    /**
     * Returns an initiliazed instance of image2 component.
     * @return the initialized component instance
     */
    public Image getImage2() {
        if (image2 == null) {//GEN-END:|87-getter|0|87-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|87-getter|1|87-@java.io.IOException
                image2 = Image.createImage("/img/more.png");
            } catch (java.io.IOException e) {//GEN-END:|87-getter|1|87-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|87-getter|2|87-postInit
            // write post-init user code here
        }//GEN-BEGIN:|87-getter|3|
        return image2;
    }
    //</editor-fold>//GEN-END:|87-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image3 ">//GEN-BEGIN:|88-getter|0|88-preInit
    /**
     * Returns an initiliazed instance of image3 component.
     * @return the initialized component instance
     */
    public Image getImage3() {
        if (image3 == null) {//GEN-END:|88-getter|0|88-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|88-getter|1|88-@java.io.IOException
                image3 = Image.createImage("/img/minus.png");
            } catch (java.io.IOException e) {//GEN-END:|88-getter|1|88-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|88-getter|2|88-postInit
            // write post-init user code here
        }//GEN-BEGIN:|88-getter|3|
        return image3;
    }
    //</editor-fold>//GEN-END:|88-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image4 ">//GEN-BEGIN:|89-getter|0|89-preInit
    /**
     * Returns an initiliazed instance of image4 component.
     * @return the initialized component instance
     */
    public Image getImage4() {
        if (image4 == null) {//GEN-END:|89-getter|0|89-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|89-getter|1|89-@java.io.IOException
                image4 = Image.createImage("/img/report.png");
            } catch (java.io.IOException e) {//GEN-END:|89-getter|1|89-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|89-getter|2|89-postInit
            // write post-init user code here
        }//GEN-BEGIN:|89-getter|3|
        return image4;
    }
    //</editor-fold>//GEN-END:|89-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: nextItemCommand ">//GEN-BEGIN:|90-getter|0|90-preInit
    /**
     * Returns an initiliazed instance of nextItemCommand component.
     * @return the initialized component instance
     */
    public Command getNextItemCommand() {
        if (nextItemCommand == null) {//GEN-END:|90-getter|0|90-preInit
            // write pre-init user code here
            nextItemCommand = new Command("Siguiente", Command.ITEM, 0);//GEN-LINE:|90-getter|1|90-postInit
            // write post-init user code here
        }//GEN-BEGIN:|90-getter|2|
        return nextItemCommand;
    }
    //</editor-fold>//GEN-END:|90-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: prevItemCommand ">//GEN-BEGIN:|92-getter|0|92-preInit
    /**
     * Returns an initiliazed instance of prevItemCommand component.
     * @return the initialized component instance
     */
    public Command getPrevItemCommand() {
        if (prevItemCommand == null) {//GEN-END:|92-getter|0|92-preInit
            // write pre-init user code here
            prevItemCommand = new Command("Anterior", Command.ITEM, 0);//GEN-LINE:|92-getter|1|92-postInit
            // write post-init user code here
        }//GEN-BEGIN:|92-getter|2|
        return prevItemCommand;
    }
    //</editor-fold>//GEN-END:|92-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: nextItemCommand1 ">//GEN-BEGIN:|105-getter|0|105-preInit
    /**
     * Returns an initiliazed instance of nextItemCommand1 component.
     * @return the initialized component instance
     */
    public Command getNextItemCommand1() {
        if (nextItemCommand1 == null) {//GEN-END:|105-getter|0|105-preInit
            // write pre-init user code here
            nextItemCommand1 = new Command("Siguiente", Command.ITEM, 0);//GEN-LINE:|105-getter|1|105-postInit
            // write post-init user code here
        }//GEN-BEGIN:|105-getter|2|
        return nextItemCommand1;
    }
    //</editor-fold>//GEN-END:|105-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: prevItemCommand1 ">//GEN-BEGIN:|107-getter|0|107-preInit
    /**
     * Returns an initiliazed instance of prevItemCommand1 component.
     * @return the initialized component instance
     */
    public Command getPrevItemCommand1() {
        if (prevItemCommand1 == null) {//GEN-END:|107-getter|0|107-preInit
            // write pre-init user code here
            prevItemCommand1 = new Command("Anterior", Command.ITEM, 0);//GEN-LINE:|107-getter|1|107-postInit
            // write post-init user code here
        }//GEN-BEGIN:|107-getter|2|
        return prevItemCommand1;
    }
    //</editor-fold>//GEN-END:|107-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand6 ">//GEN-BEGIN:|109-getter|0|109-preInit
    /**
     * Returns an initiliazed instance of backCommand6 component.
     * @return the initialized component instance
     */
    public Command getBackCommand6() {
        if (backCommand6 == null) {//GEN-END:|109-getter|0|109-preInit
            // write pre-init user code here
            backCommand6 = new Command("Atras", Command.BACK, 0);//GEN-LINE:|109-getter|1|109-postInit
            // write post-init user code here
        }//GEN-BEGIN:|109-getter|2|
        return backCommand6;
    }
    //</editor-fold>//GEN-END:|109-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: consultaSaldoForm ">//GEN-BEGIN:|104-getter|0|104-preInit
    /**
     * Returns an initiliazed instance of consultaSaldoForm component.
     * @return the initialized component instance
     */
    public Form getConsultaSaldoForm() {
        if (consultaSaldoForm == null) {//GEN-END:|104-getter|0|104-preInit
            // write pre-init user code here
            consultaSaldoForm = new Form("Consulta de Saldos");//GEN-BEGIN:|104-getter|1|104-postInit
            consultaSaldoForm.addCommand(getNextItemCommand1());
            consultaSaldoForm.addCommand(getPrevItemCommand1());
            consultaSaldoForm.addCommand(getBackCommand6());
            consultaSaldoForm.setCommandListener(this);//GEN-END:|104-getter|1|104-postInit
            // write post-init user code here
            Cuenta[] cc = cuentaController.list(reportIndex, reportPageSize);
            if (cc != null) {
                consultaSaldoForm.append(new StringItem("Pagina " + (reportIndex + 1), "\n"));
                for (int i = 0; i < cc.length; i++) {
                    consultaSaldoForm.append(new StringItem("Mes: "+cc[i].getMes() + "  Año: " + cc[i].getAnio(),
                            "\nSaldo: " + cc[i].getSaldo()+"\nIngresos:"+cc[i].getIngresos()+"\nEgresos:"+cc[i].getEgresos()));
                    consultaSaldoForm.append(new Spacer(16, 2));
                }
            } else {
                consultaSaldoForm.append(new StringItem("No se encontraron registros.", ""));
            }
        }//GEN-BEGIN:|104-getter|2|
        return consultaSaldoForm;
    }
    //</editor-fold>//GEN-END:|104-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|113-getter|0|113-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|113-getter|0|113-preInit
            // write pre-init user code here
            image = Image.createImage(1, 1);//GEN-LINE:|113-getter|1|113-postInit
            // write post-init user code here
        }//GEN-BEGIN:|113-getter|2|
        return image;
    }
    //</editor-fold>//GEN-END:|113-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image5 ">//GEN-BEGIN:|114-getter|0|114-preInit
    /**
     * Returns an initiliazed instance of image5 component.
     * @return the initialized component instance
     */
    public Image getImage5() {
        if (image5 == null) {//GEN-END:|114-getter|0|114-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|114-getter|1|114-@java.io.IOException
                image5 = Image.createImage("/img/saldo.png");
            } catch (java.io.IOException e) {//GEN-END:|114-getter|1|114-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|114-getter|2|114-postInit
            // write post-init user code here
        }//GEN-BEGIN:|114-getter|3|
        return image5;
    }
    //</editor-fold>//GEN-END:|114-getter|3|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
}
